﻿using FH.Application.PorductApp.Dtos;
using FH.Application.UserApp;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;

namespace WebSite.Controllers
{
    public class ProductController : FHController
    {
        private readonly IProductAppService _productService;
        public ProductController(IProductAppService productService
            , ISettingService settingService) : base(settingService)
        {
            _productService = productService;
        }
        public IActionResult Index(Guid? id)
        {
            int total = 0;
            List<CategoryDto> categories = _productService.GetCategoryDtos(1, 100, out total);
            List<ProductDto> products = null;
            ViewBag.Categorys = categories;
            if (categories != null && categories.Any())
            {
                if (!id.HasValue)
                {
                    id = categories[0].Id;
                }
                products = _productService.GetProducts(id, 1, 100, out total);
            }
            ViewBag.Products = products;
            ViewBag.Banners = _settingService.GetBannerPage(1, 10, out total);
            return View();
        }
        public IActionResult Data(Guid category)
        {
            int total = 0;
            List<ProductDto> products = _productService.GetProducts(category, 1, 100, out total);
            return Json(products);
        }
        public IActionResult Detail(Guid id)
        {
            int total = 0;
            ViewBag.Categorys = _productService.GetCategoryDtos(1, 100, out total);
            var product = _productService.Get(id);
            return View(product);
        }
    }
}